<?php
/**
 * Created by PhpStorm.
 * User: ruma
 * Date: 2019/2/2
 * Time: 10:46
 */

namespace app\admin\model;


use app\admin\validate\LinkValidate;
use app\common\model\AdminBaseModel;
use think\Validate;

class Link extends AdminBaseModel
{
    protected $pk = 'link_id';
    protected $table = 'link';

    /**
     * 获取数据
     */
    public function getAll() {
        return $this->order('link_sort desc,link_id desc')->paginate(10);
    }

    /**
     * 添加友链
     */
    public function addLink() {
        //验证
        $postData = (new LinkValidate())->postCheckAndGet();
        //添加
        $this->save($postData);
        return true;
    }

    /**
     * 添加友链
     */
    public function editLink() {
        //验证
        $postData = (new LinkValidate())->postCheckAndGet();
        //添加
        $this->save($postData, $postData['link_id']);

        return true;
    }

    /**
     * 删除友链
     */
    public function delLink($link_id){
        $this->where('link_id','=',$link_id)->delete();
        return true;
    }

}